
package cfar.ff.data;

import cfar.ff.fun.F1;
import java.io.Serializable;

/**
 *
 * @author badi
 */
public class Assocs {

    public static class Assoc2<A,B> implements Serializable {
        public final A $1;
        public final B $2;
        
        public Assoc2(A a, B b){
            this.$1 = a;
            this.$2 = b;
        }

        public String toString(){
            return "(" + $1 + ", " + $2 + ")";
        }
    }


    public static class Assoc3<A,B,C> extends Assoc2<A,B>{
        public final C $3;

        public Assoc3(A a, B b, C c){
            super(a, b);
            this.$3 = c;
        }

        public String toString(){
            return "(" + $1 + ", " + $2 + ", " + $3 + ")";
        }
    }


    public static <A,B> F1<Assoc2<A,B>, A> fst() {
        return new F1<Assoc2<A,B>, A>() {

            public A f(Assoc2<A, B> a) {
                return a.$1;
            }
        };
    }


    public static <A,B> F1<Assoc2<A,B>, B> snd() {
        return new F1<Assoc2<A, B>, B>() {

            public B f(Assoc2<A, B> a) {
                return a.$2;
            }
        };
    }

    public static <A,B,C> F1<Assoc3<A,B,C>, C> third() {
        return new F1<Assoc3<A, B, C>, C>() {

            public C f(Assoc3<A, B, C> a) {
                return a.$3;
            }
        };
    }

}
